function putBrowserData(data){
    /**
     * {
     *     uid:1
     *     sid:1
     * }
     */
    document.getElementById("historyList").innerHTML="";
    for(var i in data){
        var d=data[i];
        $.ajax({
            type:'get',
            url:'/item/get?id='+d.sid,
            dataType:'json',
            success:function(itemData){
                //console.log(data);
                putAHistoryData(itemData);
            },
            error:function(jqXHR){
                console.log(jqXHR);
            }
        });
    }
}

function clearBrowserData(){
    var uid = getStorage("uid");
    $.ajax({
        type:'get',
        url:'/browser/del?uid='+uid,
        dataType:'json',
        success:function(itemData){
            //console.log(data);
            document.getElementById("historyList").innerHTML="";
        },
        error:function(jqXHR){
            console.log(jqXHR);
        }
    });
}

function putAHistoryData(data){
    document.getElementById("historyList").innerHTML+="            \t<li>\n" +
        "                    <div class=\"img\">\n" +
        "                        <a href=\"#\">\n" +
        "                            <img src=\"" +
        data.sp[0].img +
        "\" width=\"185\" height=\"162\" />\n" +
        "                        </a>\n" +
        "                    </div>\n" +
        "                \t<div class=\"name\"><a href=\"#\">"+data.name+"</a></div>\n" +
        "                    <div class=\"price\">\n" +
        "                    \t<font>￥<span>"+data.lessPrice+"</span></font> &nbsp; 18R\n" +
        "                    </div>\n" +
        "                </li>";

}

function getCookie(key) {
    var s=document.cookie.split(";");
    for(var i in s){
        var tmp=s[i].split("=");
        if(tmp[0]==key){
            return tmp[1];
        }
    }


}

function getDataByUrl (name) {
    var urlData=window.location.href.split("?")[1];
    var datas=urlData.split("&");
    for (var i in datas){
        var s=datas[i].split("=");
        if(s[0]===name)
            return s[1];
    }
}

function equalsObj(obj1,obj2) {
    for(var i in obj1){
        if(obj2[i]===undefined)
            return false;
        if(obj1[i]!==obj2[i])
            return false;
    }

    for(var j in obj2){
        if(obj1[j]===undefined)
            return false;
        if(obj1[j]!==obj2[j])
            return false;
    }
    return true;
}

function setStorage(name,value) {
    window.localStorage.setItem(name,value);
}

function addArrayNotRepeat(arr,key) {
    for (var i=0;i<arr.length;i++)
    {
        if(arr[i]===key)
            return;
    }
    arr.push(key);

}

function getStorage(name) {
    return window.localStorage.getItem(name);
}